<template>
    <div class="dashboard-container">
        <h2>用户中心</h2>

        <div class="welcome-message">
            <h3>欢迎回来，{{ userName }}</h3>
            <p>在这里您可以管理个人信息、收货地址、查看竞拍记录和订单</p>
        </div>

        <div class="dashboard-cards">
            <h3>账户管理</h3>
            <el-row :gutter="20">
                <el-col :span="8">
                    <el-card shadow="hover">
                        <template #header>
                            <div class="card-header">
                                <span>个人信息</span>
                            </div>
                        </template>
                        <div class="card-body">
                            <div class="card-icon">
                                <el-icon :size="32">
                                    <User />
                                </el-icon>
                            </div>
                            <div class="card-action">
                                <router-link to="/user/profile">
                                    <el-button type="primary">查看</el-button>
                                </router-link>
                            </div>
                        </div>
                    </el-card>
                </el-col>

                <el-col :span="8">
                    <el-card shadow="hover">
                        <template #header>
                            <div class="card-header">
                                <span>收货地址</span>
                            </div>
                        </template>
                        <div class="card-body">
                            <div class="card-icon">
                                <el-icon :size="32">
                                    <Location />
                                </el-icon>
                            </div>
                            <div class="card-action">
                                <router-link to="/user/address">
                                    <el-button type="primary">管理</el-button>
                                </router-link>
                            </div>
                        </div>
                    </el-card>
                </el-col>

                <el-col :span="8">
                    <el-card shadow="hover">
                        <template #header>
                            <div class="card-header">
                                <span>前往市场</span>
                            </div>
                        </template>
                        <div class="card-body">
                            <div class="card-icon">
                                <el-icon :size="32">
                                    <Shop />
                                </el-icon>
                            </div>
                            <div class="card-action">
                                <router-link to="/market">
                                    <el-button type="primary">浏览</el-button>
                                </router-link>
                            </div>
                        </div>
                    </el-card>
                </el-col>
            </el-row>

            <h3 style="margin-top: 30px;">交易管理</h3>
            <el-row :gutter="20">
                <el-col :span="8">
                    <el-card shadow="hover">
                        <template #header>
                            <div class="card-header">
                                <span>我的竞拍</span>
                            </div>
                        </template>
                        <div class="card-body">
                            <div class="card-icon">
                                <el-icon :size="32">
                                    <Ticket />
                                </el-icon>
                            </div>
                            <div class="card-action">
                                <router-link to="/user/bids">
                                    <el-button type="primary">查看</el-button>
                                </router-link>
                            </div>
                        </div>
                    </el-card>
                </el-col>

                <el-col :span="8">
                    <el-card shadow="hover">
                        <template #header>
                            <div class="card-header">
                                <span>我的订单</span>
                            </div>
                        </template>
                        <div class="card-body">
                            <div class="card-icon">
                                <el-icon :size="32">
                                    <ShoppingCart />
                                </el-icon>
                            </div>
                            <div class="card-action">
                                <router-link to="/user/orders">
                                    <el-button type="primary">查看</el-button>
                                </router-link>
                            </div>
                        </div>
                    </el-card>
                </el-col>
            </el-row>

            <!-- 卖家功能区块 -->
            <template v-if="userStore.isSeller">
                <h3 style="margin-top: 30px;">卖家功能</h3>
                <el-row :gutter="20">
                    <el-col :span="8">
                        <el-card shadow="hover">
                            <template #header>
                                <div class="card-header">
                                    <span>卖家中心</span>
                                </div>
                            </template>
                            <div class="card-body">
                                <div class="card-icon">
                                    <el-icon :size="32">
                                        <DataAnalysis />
                                    </el-icon>
                                </div>
                                <div class="card-action">
                                    <router-link to="/user/seller">
                                        <el-button type="primary">查看</el-button>
                                    </router-link>
                                </div>
                            </div>
                        </el-card>
                    </el-col>

                    <el-col :span="8">
                        <el-card shadow="hover">
                            <template #header>
                                <div class="card-header">
                                    <span>发布拍卖品</span>
                                </div>
                            </template>
                            <div class="card-body">
                                <div class="card-icon">
                                    <el-icon :size="32">
                                        <Plus />
                                    </el-icon>
                                </div>
                                <div class="card-action">
                                    <router-link to="/user/seller/auction/publish">
                                        <el-button type="primary">发布</el-button>
                                    </router-link>
                                </div>
                            </div>
                        </el-card>
                    </el-col>

                    <el-col :span="8">
                        <el-card shadow="hover">
                            <template #header>
                                <div class="card-header">
                                    <span>我的拍卖品</span>
                                </div>
                            </template>
                            <div class="card-body">
                                <div class="card-icon">
                                    <el-icon :size="32">
                                        <Goods />
                                    </el-icon>
                                </div>
                                <div class="card-action">
                                    <router-link to="/user/seller/auctions">
                                        <el-button type="primary">管理</el-button>
                                    </router-link>
                                </div>
                            </div>
                        </el-card>
                    </el-col>
                </el-row>
            </template>

            <!-- 非卖家显示申请入口 -->
            <template v-else>
                <h3 style="margin-top: 30px;">成为卖家</h3>
                <el-row :gutter="20">
                    <el-col :span="8">
                        <el-card shadow="hover">
                            <template #header>
                                <div class="card-header">
                                    <span>申请成为卖家</span>
                                </div>
                            </template>
                            <div class="card-body">
                                <div class="card-icon">
                                    <el-icon :size="32">
                                        <Shop />
                                    </el-icon>
                                </div>
                                <div class="card-desc">
                                    <p>成为卖家，发布您的拍卖品</p>
                                </div>
                                <div class="card-action">
                                    <router-link to="/user/seller/apply">
                                        <el-button type="success">立即申请</el-button>
                                    </router-link>
                                </div>
                            </div>
                        </el-card>
                    </el-col>
                </el-row>
            </template>
        </div>
    </div>
</template>

<script setup>
import { computed } from 'vue'
import { useUserStore } from '@/stores/user'

const userStore = useUserStore()
const userName = computed(() => userStore.name || userStore.username || '用户')
</script>

<style scoped>
.dashboard-container {
    padding: 20px;
}

.welcome-message {
    margin-bottom: 30px;
    padding: 20px;
    background-color: #f2f6fc;
    border-radius: 8px;
}

.welcome-message h3 {
    margin-top: 0;
    color: #409EFF;
}

.dashboard-cards {
    margin-top: 20px;
}

.dashboard-cards h3 {
    margin-bottom: 20px;
    color: #606266;
    border-bottom: 1px solid #EBEEF5;
    padding-bottom: 10px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;
}

.card-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 120px;
}

.card-icon {
    margin-bottom: 20px;
    color: #409EFF;
}

.card-desc {
    text-align: center;
    margin-bottom: 10px;
    color: #606266;
}

.el-row {
    margin-bottom: 20px;
}
</style>